<?php
namespace Common\Model;
use Think\Model;

class CategoryModel extends Model{
	/**
	 * 获取类别名称
	 * @param  [type] $id 类别ID
	 */
	public function get_name($id){
		$where['id'] = $id;
		$name = $this->where($where)->getField('title');
		return $name?$name:'';
	}
	/**
	 * 获取类别图标
	 * @param  [type] $id 类别ID
	 */
	public function get_ico($id){
		$where['id'] = $id;
		$images_id = $this->where($where)->getField('images_id');
		return D('File')->get_path($images_id);
	}
	/**
	 * 获取模块类别列表
	 * @param  string $module 模块
	 */
	public function get_list($module = 'credentials', $num = ''){
		$where['module']  = $module;
		$where['status']  = 1;
		$list = D('Category')->field('id,title,is_input_text,images_id,description')
							 ->where($where)
							 ->order('order_id,id desc')
							 ->limit($num)
							 ->select();
		$data = array();
		foreach ($list as $rs) {
			$rs['is_input_text'] = $rs['is_input_text']==1;
			$rs['images_url']    = D('File')->get_path($rs['images_id']);
			$rs['description']   = $rs['description']?$rs['description']:'';
			$data[] = $rs;
		}
		return $data;
	}
	/**
	 * 判断是否要输入其它原因
	 * @param  [type]  $category_id 类型ID
	 * @return boolean              [description]
	 */
	public function is_input_text($category_id){
		$where['id'] = $category_id;
		$count = D('Category')->where($where)->getField('is_input_text');
		return $count > 0;
	}
	/**
	 * 判断ID是否存在
	 * @param  string  $id 类别ID
	 * @return boolean     [description]
	 */
	public function is_exists_id($id='', $module=''){
		$where['id'] = $id;
		if($module){
			$where['module'] = $module;
		}
		$count = $this->where($where)->count();
		return $count > 0;
	}
}
?>